<template>
  <div class="salesInfo">
    <div style="height: 800px">
      <FormPanel
        ref="formPanel"
        :cols="3"
        :labelWidth="100"
        :list="formList"
        formType="show"
        :isSubmitBtn="false"
        @formChange="formChangeHandle"
        style="margin-top: 20px"
      />
      <p style="border-top:1px dashed #ccc;">
      <div>
        <div class="noticeRuleDiv" >
            <span class="noticeRuleSpan"><i style="color:red;">*</i> 营业时间</span>
            <el-time-select
              placeholder="起始时间"
              v-model="businessBeginHours"
              :picker-options="{
                start: '00:00',
                step: '00:15',
                end: '24:00'
              }">
            </el-time-select>
            <el-time-select
              placeholder="结束时间"
              v-model="businessEndHours"
              :picker-options="{
                start: '00:00',
                step: '00:15',
                end: '24:00',
                minTime: businessBeginHours
              }">
            </el-time-select>
        </div>
        <FormPanel
        ref="formPanelImg"
        :list="formListImg"
        :cols="1"
        formType="edit"
        :isSubmitBtn="false"
      />
      </div>
      <p style="border-top:1px dashed #ccc;">
      <p class="duty">授权</p>
      <BrandInfo   :isOk="isOk"/>
      <div style="text-align: center; margin: 10px;">
        <el-button  @click="saveDialog()" type="primary">保 存</el-button>
      </div>
    </div>
    
    
  </div>
</template>

<script>
// import {getDealerCompanyByCode } from "@/api/common/org/dealerCompany";
import { dictionary } from '@/utils/dictMixin';
import BrandInfo from './brandInfo'
import { getDealerCompanyByCode,getlistAllData,dealerPictures,postDealerPicture} from "@/api/common/org/dealerCompany";
export default {
  name: 'SalesInfo',
  mixins: [dictionary],
  components: {
    BrandInfo
  },
  /* props: {
    rowData: {
      type: Object,
      default: () => ({})
    },
    listAllData:{
      type:Array,
      default:()=>([])
    },
    isOk:{
      type:Boolean,
      default:false
    },
  }, */
  data() {
    this.saveData = null;
    return {
      visible: false,
      formList: this.createFormList(),
      formListImg:this.createFormListImg(),
      listAllData:[],
      isOk:false,
      businessBeginHours: '08:30',
      businessEndHours: '18:30',
      infoArr:null,
    };
  },
  computed: {

  },
  watch: {
      isOk(oldval,newval){
        if(oldval){
          this.formList.forEach(ele => {
            this.listAllData.forEach(x=>{
              if(x.regionId == ele.initialValue){
                ele.initialValue=x.regionName
              }
            })
          });
        }
      }
  },
  created() {
    this.getDealer();
  },
  methods: {
    async getDealer() {
      let res = await getDealerCompanyByCode();
      this.infoArr=res.data
      this.formList.forEach(x => {
        x.initialValue = res.data[x.fieldName];
      });
      this.formList.find(item=>item.fieldName == "distributorLevel").initialValue = Number(res.data['distributorLevel'])
      this.formList.find(item=>item.fieldName == "validStatus1").initialValue = Number(res.data['validStatus1'])
      this.formList.find(item=>item.fieldName == "businessStatus").initialValue = Number(res.data['businessStatus'])
      await getlistAllData().then(res=>{
         this.listAllData=res.data
        //  this.rowData= res.data.listOBSVO
         this.isOk=true
       })

      let params = {
        dealerCodes:res.data.dealerCode,
        dealerIds:'',
      }
       dealerPictures(params).then(res=>{
         if(res.success){
           console.log(res,"res")
           res.data.forEach(x=>{
             this.businessBeginHours=x.businessBeginHours
             this.businessEndHours=x.businessEndHours
             this.formListImg.find(x=>x.fieldName == 'dealerPicture').initialValue = [`${x.dealerPicture}`]
           })
         }
       })
    },
    createFormListImg() {
      return [
        {
          type: 'UPLOAD_IMG',
          label: '门店照片',
          disabled: this.type === 'show'?true:false,
          fieldName: 'dealerPicture',
          placeholder: '请上传门店照片',
          initialValue:[''],
          // style: { width: '250px' },
          rules: [{ required: true, message: '请上传门店照片', trigger: 'change' }],
          upload: {
            actionUrl: '/api/file/oss/upload',
            fixedSize: [5, 2],
            isCalcHeight: true,
          }
        },
      ];
    },
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'dealerCode',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          initialValue: '',
          //itemList: this.createDictList('1004')
        },
        {
          type: 'INPUT',
          label: '经销商简称',
          fieldName: 'dealerShortname',
          initialValue: '',
        },
        {
          type: 'SELECT',
          label: '经销商级别',
          fieldName: 'distributorLevel',
          initialValue: '',
          itemList: this.createDictList('2540')
        },
        {
          type: 'SELECT',
          label: '经销商类型',
          fieldName: 'agType',
          initialValue: '',
          itemList: this.createDictList('2538')
        },
        {
          type: 'INPUT',
          label: '开票经销商',
          fieldName: 'taxNo',
          initialValue: '',
        },
        {
          type: 'SELECT',
          label: '经销商状态',
          fieldName: 'validStatus1',
          placeholder: '请选择',
          itemList: this.createDictList('1001'),
          //rules: [{ required: true, message: '请选择是否有效', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '经销商营业状态',
          fieldName: 'businessStatus',
          initialValue: '',
          itemList: this.createDictList('1011')
        },
        {
          type: 'INPUT',
          label: '传真',
          fieldName: 'faxNo',
          initialValue: '',
        },
        /* {
          type: 'SELECT',
          label: '是否授权',
          fieldName: 'isAuz',
          initialValue: '',
          itemList: this.createDictList('1544')
        }, */
        {
          type: 'INPUT',
          label: '联系人',
          fieldName: 'linkMan',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '联系电话',
          fieldName: 'phone1',
          initialValue: '',
        },
        
        {
          type: 'INPUT',
          label: '邮编',
          fieldName: 'zipCode1',
          initialValue: '',
        },
        
        {
          type: 'SELECT',
          label: '所属区域',
          fieldName: 'saleArea',
          initialValue: '',
          itemList: this.createDictList('1544')
        },
        {
          type: 'INPUT',
          label: '省',
          fieldName: 'provinceId1',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '市',
          fieldName: 'cityId1',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '区/县',
          fieldName: 'countyId',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '地址',
          fieldName: 'address',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '经度',
          fieldName: 'latitude',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '纬度',
          fieldName: 'longitude',
          initialValue: '',
        },
        
      ];
    },
    saveDialog(){
      let params={
        businessBeginHours:this.businessBeginHours,
        businessEndHours:this.businessEndHours,
        dealerPicture:this.formListImg.find(x=>x.fieldName == 'dealerPicture').initialValue[0],
        dealerCode:this.infoArr.dealerCode ,
        dealerId:"",
        dealerName:this.infoArr.dealerName ,
      }
      postDealerPicture(params).then(res=>{
        if(res.success){
          this.$message.success('保存成功');
        }
      })
    },
    formChangeHandle(val) {
      this.saveData = val;
    },

  }

};
</script>
<style scoped lang="less">
.salesInfo{
  .duty{
    line-height: 40px;
    background: #eee;
    padding-left: 20px;
  }
  .noticeRuleDiv{
        margin: 10px 0 10px 14px;
        font-size: 12px;
        .noticeRuleSpan{
            display: inline-block;
            margin-right: 7px;
            // width: 13%;
        }
    }
    .saveHandle{
        margin:30px 0 10px 11%;
    }
}    
</style>
